// src/store/user.ts
import { defineStore } from "pinia"

const useCommonStore = defineStore({
	id: "commonStore",
	state: () => {
		return {
			region_id: uni.getExtConfigSync().region_id, //目的地ID
			region_name: uni.getExtConfigSync().region_name,
			showLoading: false,
			showLogin: false,
			navbarHeight: 44, // 原生标题栏高度44px
			tabbarHeight: 50, // 底部tabbar高度50px
			statusBarHeight: 0,
			safeAreaBottomHeight: 0,
			preventViewflag: false, //数字组件blur时会点击到页面影响实际效果,focus时页面弹窗一个透明遮罩blur时取消,从而阻止页面点击
			desensitize: !!uni.getStorageSync("desensitize"), //金额脱敏状态
		}
	},
	actions: {
		updateShowLoading(payload: boolean) {
			this.showLoading = payload
		},
		updateShowLogin(payload: boolean) {
			this.showLogin = payload
		},
		updateStatusBarHeight(height: number) {
			this.statusBarHeight = height
		},
		updateSafeAreaBottomHeight(height: number) {
			this.safeAreaBottomHeight = height
		},
		updatePreventViewFlag(payload: boolean) {
			this.preventViewflag = payload
		},
		updateDesensitize(value: boolean) {
			this.desensitize = value
			uni.setStorageSync("desensitize", value)
		},
	},
})

export default useCommonStore
